package cn.highedu.coolshark.product.controller;

import cn.highedu.coolshark.common.JsonResult;
import cn.highedu.coolshark.common.PagedVO;
import cn.highedu.coolshark.product.pojo.dto.SpuAddNewDTO;
import cn.highedu.coolshark.product.pojo.dto.SpuQueryParamDTO;
import cn.highedu.coolshark.product.pojo.vo.SpuListItemVO;
import cn.highedu.coolshark.product.service.ISpuService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/spus")
@Slf4j
public class SpuController {
    @Autowired
    private ISpuService spuService;

    @PostMapping("/add-new")
    @ApiOperation("添加SPU")
    @ApiImplicitParam(name = "spuAddNewDTO", value = "SPU新增数据传输对象", required = true, dataType = "SpuAddNewDTO")
    public JsonResult<Void> addNew(@RequestBody SpuAddNewDTO spuAddNewDTO) {
        log.debug("开始处理【添加SPU】的请求, 参数: {}", spuAddNewDTO);
        spuService.addNew(spuAddNewDTO);
        log.debug("添加SPU成功");
        return JsonResult.ok();
    }
    /**
     * 分页查询SPU列表
     */
    @PostMapping("/paged")
    @ApiOperation("分页查询SPU列表")
    @ApiImplicitParam(name = "spuQueryParamDTO", value = "SPU查询数据传输对象", required = true, dataType = "SpuQueryParamDTO")
    public JsonResult<PagedVO<SpuListItemVO>> list(@RequestBody SpuQueryParamDTO spuQueryParamDTO) {
        log.debug("开始处理【分页查询SPU列表】的请求, 参数: {}", spuQueryParamDTO);
        PagedVO<SpuListItemVO> pagedVO = spuService.list(spuQueryParamDTO);
        return JsonResult.ok(pagedVO);
    }
}
